package com.fighthouse.utils
{
	import com.fighthouse.entity.FotoNoticia;
	
	import mx.containers.Canvas;
	import mx.controls.CheckBox;
	import mx.controls.Image;
	import mx.core.Application;
	import mx.core.ScrollPolicy;
	import mx.core.UIComponent;
	
	public class FotoNoticiaRender extends Canvas
	{
		private var frame:UIComponent;
		private var selection:UIComponent;
		private var _foto:Image;
		public var _check:CheckBox;
		
		private var foto:FotoNoticia;
		
		private var margin:Number = 2;
		
		public function FotoNoticiaRender()
		{
			super();
			
			this.verticalScrollPolicy = ScrollPolicy.OFF;
			this.horizontalScrollPolicy = ScrollPolicy.OFF;
			
			frame = new UIComponent();
			frame.graphics.beginFill(0xFFFFFF,.2);
			frame.graphics.lineStyle(1,0,.45);
			frame.graphics.drawRect(0,0,20,20);
			frame.graphics.endFill();
			frame.graphics.lineStyle(1,0xFFFFFF,.48);
			frame.graphics.drawRect(-1,1,20,20);
			frame.mouseEnabled = false;
			frame.mouseChildren = false;
			addChild(frame);
			
			_foto = new Image();
			_foto.setStyle("focusThickness",1);
			_foto.autoLoad = true;
			_foto.mouseEnabled = false;
			_foto.mouseChildren = false;
			addChild(_foto);
			
			_check = new CheckBox();
			addChild(_check);
		}
		
		public function set dataProvider(value:FotoNoticia):void
		{
			foto = value;
			/* var r:String = Application.application.url.substring(0,Application.application.url.lastIndexOf("/"))
			+"/assets/atletas/"+foto.atleta.id+"/thumbs/"+foto.arquivo; */
			_foto.source = Application.application.url.substring(0,Application.application.url.lastIndexOf("/"))
			+"/assets/noticias/"+foto.noticia.id+"/thumbs/"+foto.arquivo;	
		}
		
		public function get dataProvider():FotoNoticia
		{
			return foto;
		}
		
		public function set selected(b:Boolean):void
		{
			_check.invalidateProperties();
		}
		
		public function get selected():Boolean
		{
			return _check.selected;
		}
		
		override public function set data(value:Object):void
		{
			dataProvider = value as FotoNoticia;
		}
		
		override public function get data():Object
		{
			return dataProvider;
		}
		
		override protected function updateDisplayList(uW:Number, uH:Number):void
		{
			super.updateDisplayList(uW,uH);
			
			frame.graphics.clear();
			frame.graphics.beginFill(0xFFFFFF,.2);
			frame.graphics.lineStyle(1,0,.45);
			frame.graphics.drawRect(margin + 1,margin + 1,uW - 1 - margin,uH - 1 - margin);
			frame.graphics.endFill();
			frame.graphics.lineStyle(1,0xFFFFFF,.48);
			frame.graphics.drawRect(margin,margin,uW - margin,uH - margin);
			
			_foto.x = margin + 2;
			_foto.y = margin + 2;
			_foto.height = uH - _foto.y;
			//_foto.width = 86;	// = 76;
			
			_check.x = uW - 14 - margin;
			_check.y = uH - 14 - 5;
			
		}
	}
}